//
//  YSBaseViewController.m
//  Yaoyle
//
//  Created by ZhaoXudong on 14-9-15.
//  Copyright (c) 2014年 ZhaoXudong. All rights reserved.
//

#import "YSBaseViewController.h"
#import "MBProgressHUD.h"

@interface YSBaseViewController () {
}

@end

@implementation YSBaseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_all"]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showBackBtnWithFrame:(CGRect)frame {
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"back_btn"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
}

- (void)backBtnClick {
}

- (void)showMsgWithTitle:(NSString *)title msg:(NSString *)msg {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:msg
                                                   delegate:nil
                                          cancelButtonTitle:@"确定"
                                          otherButtonTitles:nil, nil];
    [alert show];
}

- (void)showMsgWithTitle:(NSString *)title msg:(NSString *)msg delegate:(id)delegate tag:(NSInteger)tag{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:msg
                                                   delegate:delegate
                                          cancelButtonTitle:@"取消"
                                          otherButtonTitles:@"确定", nil];
    alert.tag = tag;
    [alert show];
}

- (void)navigationController:(UINavigationController *)navigationController
      willShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {
    [navigationController setNavigationBarHidden:YES animated:animated];
}

- (void) didFail:(NetworkMgr *)api userInfo:(NSDictionary *)info {
    [YSProgressHUD hideHUDForView:self.view];
    if (![YSUtility isBlankObject:info[@"status"]]) {
        NSInteger status = [info[@"status"] integerValue];
        if (status == 910) {
            [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationLoginOut
                                                                            object:nil];
        } else {
            [self showMsgWithTitle:nil msg:info[@"msg"]];
        }
    }
}

- (void)showToastMessage:(NSString *)message
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithFrame:self.view.bounds];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = message;
    hud.labelFont = [UIFont boldSystemFontOfSize:14];
    [self.view addSubview:hud];
    [hud show:YES];
    [hud hide:YES afterDelay:1.5];
}
@end
